package xdu.lz.stage6_threadpool.chapter3_threadPoolExecutorAPI.myFuture;

import java.util.concurrent.Callable;

/**
 * Created at 2019/10/24 0024 下午 4:48
 * --
 */
class MyTask implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("the task is runnig");
        Thread.sleep(3000);
        System.out.println("the task is finished");
        return "DONE";
    }
}
public class Test {

    public static void main(String[] args) throws InterruptedException {
        MyTask myTask = new MyTask();
        FutureTask<String> future = new FutureTask<>(myTask);
        FutureTask<String> future1 = new FutureTask<>(myTask,()->{
            System.out.println("任务完成后会自动通知！");
        });
        new Thread(future).start();
        new Thread(future1).start();
        System.out.println("================");
        System.out.println("futureTask = " + future.get());
        System.out.println("*****************");
    }

}
